package com.solarStruggle.domain;

object Galaxy {
  val Size = 256;
}

@serializable
class Galaxy(_solarSystems: Array[SolarSystem], _wormholes: Array[Wormhole]) {
  /**
   * The solar systems which make up the galaxy
   */
  var solarSystems = _solarSystems
  
  /**
   * Possible wormhole connectionns between solarsystems
   */
  val wormholes = _wormholes
  
  /**
   * Regions associated with each solarsystem
   */
  val solarSystemRegions = new Array[Array[Int]](Galaxy.Size, Galaxy.Size)
  
  for(x <- 0 until Galaxy.Size; y <- 0 until Galaxy.Size) {
    var minDist: Double = Math.sqrt(2.0d * Math.pow(Galaxy.Size.toDouble, 2.0d))
    var closestIdx: Int = -1
    for(i <- 0 until solarSystems.size) {
      val s = solarSystems(i)
      val d = Math.sqrt(Math.pow(x.toDouble - s.x.toDouble, 2.0d) +
                        Math.pow(y.toDouble - s.y.toDouble, 2.0d))
      if(d < minDist) {
        minDist = d
        closestIdx = i
      }
    }
    solarSystemRegions(x)(y) = closestIdx
  }
}
